package com.bjc.platform.web.controller;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bjc.platform.service.AdmLogService;
import com.bjc.platform.util.JSONHelper;
import com.bjc.platform.util.Page;
import com.bjc.platform.util.StaticMethod;
import com.bjc.platform.vo.AdmLogSearchCondition;

@Controller
@RequestMapping("/log")
public class AdmLogController extends BaseController {

	@Autowired
	private AdmLogService admLogService;

	@RequestMapping(value = "/query", method = RequestMethod.GET)
	@ResponseBody
	public Object query(@RequestParam("page") int page,
			@RequestParam("start") int start, @RequestParam("limit") int limit,
			@RequestParam HashMap<String, Object> reqParam) throws Exception {
		AdmLogSearchCondition cond = (AdmLogSearchCondition) JSONHelper
				.json2Object(reqParam.get("condition").toString(),
						AdmLogSearchCondition.class);
		// if (json != null && !json.isNullObject()) {
		// cond = new AdmLogSearchCondition();
		// cond.setFromDate(StaticMethod.object2Date(json.get("fromDate")));
		// cond.setToDate(StaticMethod.object2Date(json.get("toDate")));
		// cond.setUname(json.getString("uname"));
		// }

		PageRequest pr = new PageRequest(page - 1, limit);
		Page userPage = admLogService.search(cond, pr);

		return StaticMethod.TOListJSONResult(true, userPage.getResult(),
				userPage.getTotalCount()).getJSONResult();
	}

}
